Proot-Write-Init(){

## 写入
cat > $SH <<EOF
#!/system/bin/sh

# 容器根路径
PROOT_ROOTFS_DIR="$RELEASE_PATH"

# 设置缓存目录
PROOT_EXTRA_DIR="$PL_EXTRA_DIR"

# 发行版名称
RELEASE_NAME="$RELEASE_NAME"

# 设置 link2symlink 目录
MKDIR_L2S="\$PROOT_EXTRA_DIR/meta/\$RELEASE_NAME"

# 设置 proot 临时目录
MKDIR_TMP="\$PROOT_EXTRA_DIR/tmp/\$RELEASE_NAME"

# 创建 proc
PROOT_ROOTFS_PROC="$TTB_PROOT_PROC"
PROC=""
for i in \$(cd \$PROOT_ROOTFS_PROC && echo *);do
  PROC=\${PROC}" -b \$PROOT_ROOTFS_PROC/\$i:/proc/\$i"
done


## 设置 proot 启动参数

# 可执行文件
command="$(command -v proot)"

# 长短参数
command=\${command}" --sysvipc"
command=\${command}" --link2symlink"
command=\${command}" --kill-on-exit"
command=\${command}" -0"
command=\${command}" -p"
command=\${command}" -L"
command=\${command}" -H"

# 使用的容器位置
command=\${command}" -r \$PROOT_ROOTFS_DIR"

# 挂载目录
command=\${command}" -b /dev"
command=\${command}" -b /proc"
command=\${command}" \$PROC"
command=\${command}" -b \$TMPDIR:/tmp"
command=\${command}" -b \$TMPDIR:/dev/shm"
command=\${command}" -b /data:/data"
command=\${command}" -b /sdcard:/sdcard"

# 容器内默认目录
command=\${command}" -w /root"

# 环境变量
command=\${command}" /usr/bin/env"
command=\${command}" HOSTNAME=\$(getprop ro.product.model)"
command=\${command}" HOME=/root"
command=\${command}" LANG=zh_CN.UTF-8"
command=\${command}" PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
command=\${command}" TMPDIR=/tmp"
command=\${command}" COLORTERM=\$COLORTERM"
command=\${command}" TERM=\$TERM"
command=\${command}" SHELL=$INIT_SHELL"
command=\${command}" SHLVL=\$SHLVL"

# 登录 Shell
command=\${command}" $INIT_SHELL -l"



## unset...
unset LD_PRELOAD
unset \$(env | tr = ' ' | awk '{print \$1}')



# mkdir...
mkdir -p \
  \$MKDIR_TMP \
  \$MKDIR_L2S



## 启动
PROOT_TMP_DIR="\$MKDIR_TMP" \
PROOT_L2S_DIR="\$MKDIR_L2S" \
exec \$command "\$@"
EOF

## 赋权
chmod +x $SH
}